﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
    <script>
        layui.use(['jquery', 'form', 'table', 'common', 'tablePlug', "layer"], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                layer = layui.layer,
                common = layui.common;
            //加载数据
            var loading = layer.load(0, { shade: false });
            common.rendertable({
                elem: '#currentTableId',
                url: '/SystemSecurity/OpenJobs/GetGridJson',
                page: false,
                sqlkey: 'F_Id',//数据库主键
                cols: [[
                    { field: 'F_Id', title: 'ID', sort: true, fixed: "left", hide: true, hideAlways: true },
                    { field: 'F_JobName', title: '名称', Width: 100 },
                    { field: 'F_JobGroup', title: '组名', Width: 100 },
                    { field: 'F_FileName', title: '文件名', Width: 150 },
                    { field: 'F_CronExpress', title: 'CRON', Width: 150 },
                    {
                        field: 'F_StarRunTime', title: '最近启动时间', Width: 180,
                        templet: function (d) {
                            if (d.F_StarRunTime) {
                                var time = new Date(d.F_StarRunTime);
                                return time.Format("yyyy-MM-dd hh:mm:ss");
                            }
                        }
                    },
                    {
                        field: 'F_EndRunTime', title: '最近关闭时间', Width: 180,
                        templet: function (d) {
                            if (d.F_EndRunTime) {
                                var time = new Date(d.F_EndRunTime);
                                return time.Format("yyyy-MM-dd hh:mm:ss");
                            }
                        }
                    },
                    {
                        field: 'F_EnabledMark', title: '状态', width: 80, sort: true,
                        templet: function (d) {
                            if (d.F_EnabledMark == true) {
                                return "<span class=\"layui-bg-green\">启动</span>";
                            } else {
                                return "<span class=\"layui-bg-red\">关闭</span>";
                            }
                        }
                    },
                    { field: 'F_Description', title: '备注', minWidth: 150 },
                ]],
                done: function () {
                    //权限控制
                    common.authorizeButton("toolbar");
                    //关闭加载
                    layer.closeAll('loading');
                }
            });
            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                //执行搜索重载
                common.reloadtable({
                    elem: 'currentTableId',
                    page: false,
                    curr: 1,
                    where: { keyword: data.field.txt_keyword }
                });
                return false;
            });
            var entity;
            table.on('row(currentTableFilter)', function (obj) {
                obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
                entity = obj;
            })
            /**
             * toolbar监听事件
             */
            table.on('toolbar(currentTableFilter)', function (obj) {
                if (obj.event === 'add') {  // 监听删除操作
                    common.modalOpen({
                        title: "添加任务",
                        url: "/SystemSecurity/OpenJobs/Form",
                        width: "550px",
                        height: "500px",
                    });
                }
                else if (obj.event === 'delete') {
                    if (entity == null) {
                        common.modalMsg("未选中数据", "warning");
                        return false;
                    }
                    common.deleteForm({
                        url: "/SystemSecurity/OpenJobs/DeleteForm",
                        param: { keyValue: entity.data.F_Id },
                        success: function () {
                            common.reload('data-search-btn');
                        }
                    });
                }
                else if (obj.event === 'edit') {
                    if (entity == null) {
                        common.modalMsg("未选中数据", "warning");
                        return false;
                    }
                    common.modalOpen({
                        title: "修改任务",
                        url: "/SystemSecurity/OpenJobs/Form?keyValue=" + entity.data.F_Id,
                        width: "550px",
                        height: "500px",
                    });
                }
                else if (obj.event === 'disabled') {
                    if (entity == null) {
                        common.modalMsg("未选中数据", "warning");
                        return false;
                    }
                    if (entity.data.F_EnabledMark!=true) {
                        common.modalMsg("任务未启动，无法关闭！", "warning");
                        return false;
                    }
                    common.modalConfirm("注：您确定要【关闭】该项任务吗？", function (r) {
                        if (r) {
                            common.submitForm({
                                url: "/SystemSecurity/OpenJobs/ChangeStatus",
                                param: { keyValue: entity.data.F_Id, status: 0},
                                close: false,
                                success: function () {
                                    common.reload('data-search-btn');
                                }
                            })
                        }
                    });
                }
                else if (obj.event === 'enabled') {
                    if (entity == null) {
                        common.modalMsg("未选中数据", "warning");
                        return false;
                    }
                    if (entity.data.F_EnabledMark == true) {
                        common.modalMsg("任务已启动，无法启动！", "warning");
                        return false;
                    }
                    common.modalConfirm("注：您确定要【启动】该项任务吗？", function (r) {
                        if (r) {
                            common.submitForm({
                                url: "/SystemSecurity/OpenJobs/ChangeStatus",
                                param: { keyValue: entity.data.F_Id, status: 1 },
                                close: false,
                                success: function () {
                                    common.reload('data-search-btn');
                                }
                            })
                        }
                    });
                }
                return false;
            });
        });
    </script>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            @*<legend>搜索信息</legend>*@
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字:</label>
                            <div class="layui-input-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container" id="toolbar">
                <button id="NF-add" authorize="yes" class="layui-btn layui-btn-sm data-add-btn layui-hide" lay-event="add"><i class="layui-icon">&#xe654;</i>新建</button>
                <button id="NF-edit" authorize="yes" class="layui-btn layui-btn-sm layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                <button id="NF-delete" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                <button id="NF-enabled" authorize="yes" class="layui-btn layui-btn-sm data-enabled-btn layui-hide" lay-event="enabled"> <i class="fa fa-play-circle"></i>启动</button>
                <button id="NF-disabled" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger data-disabled-btn layui-hide" lay-event="disabled"><i class="fa fa-stop-circle"></i>关闭</button>

            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>